﻿using System.ComponentModel;
using System.Runtime.Serialization;
using Renren.Models;
using Renren.Common;
using System;
using System.Collections.Generic;

namespace Renren.ViewModels
{
    public abstract class ViewModel : Entity
    {
        public abstract void Update(Model model);
    }

    public abstract class ViewModel<T> : Entity where T : Model
    {
        public ViewModel() { }
        public ViewModel(T model)
        {
            this.Model = model;
        }

        public T Model
        {
            get
            {
                if (_model == null)
                {
                    throw new NullReferenceException();
                }
                return _model;
            }
            set
            {
                if (value == null)
                {
                    throw new NullReferenceException();
                }
                if (PropertyNames != null || PropertyNames.Count > 0)
                {
                    foreach (var propertyName in PropertyNames)
                    {
                        NotifyPropertyChanged(propertyName);
                    }
                }
                _model = value;
            }
        }

        public override long Id
        {
            get { return Model.Id; }
        }

        protected abstract List<string> PropertyNames { get; }

        private T _model;
    }
}
